import csv
l1=[]
while 1:
    username=input('请输入用户名:')
    if username.upper()=='N':break
    password=input('请输入密码:')
    dic={}
    dic['username']=username
    dic['password']=password
    l1.append(dic)
print(l1)

csv_fp=open('用户.csv','w')
sheet_title=l1[0].keys()
sheet_data=[]
for i in l1:
    sheet_data.append(i.values())
writer=csv.writer(csv_fp)
writer.writerow(sheet_title)
writer.writerows(sheet_data)
csv_fp.close()
